From 21430de47d7f02f0a53b1e11f959a6d100bc52c7 Mon Sep 17 00:00:00 2001 From: James Henstridge Date: Sat, 9 Dec 2000 11:10:41 +0000 Subject: [PATCH] add prot struct member to hold masks for detecting the start of a protocol 2000-12-09 James Henstridge * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct member to hold masks for detecting the start of a protocol packet. (mouse_devs): add packet start masks for ps2 and ms device types. Left the mask for fidmour blank, as I have no idea what it should be. (handle_mouse_io): skip bytes until we get to the start of a packet. My Logitech mouse seems to be passing an extra NULL pad byte, and GPM does a similar thing here. (gdk_fb_mouse_ms_open): changed error message to not say psaux, as this is the ms mouse driver. (gdk_fb_mouse_ms_packet): fix up button handling, which was completely broken except for button1. It was checking the wrong bit in the packet for the status of the right mouse button, and wrongly assuming right == button2 rather than 3. I fixed that and also added support for middle button (button2). --- ChangeLog | 18 +++++++++++++ ChangeLog.pre-2-0 | 18 +++++++++++++ ChangeLog.pre-2-10 | 18 +++++++++++++ ChangeLog.pre-2-2 | 18 +++++++++++++ ChangeLog.pre-2-4 | 18 +++++++++++++ ChangeLog.pre-2-6 | 18 +++++++++++++ ChangeLog.pre-2-8 | 18 +++++++++++++ gdk/linux-fb/gdkmouse-fb.c | 54 ++++++++++++++++++++++++++++++++------ 8 files changed, 172 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 3f1fb72109..d729ce1978 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,21 @@ +2000-12-09 James Henstridge + + * gdk/linux-fb/gdkmouse-fb.c (GdkFBMouseDevice): add prot struct + member to hold masks for detecting the start of a protocol packet. + (mouse_devs): add packet start masks for ps2 and ms device types. + Left the mask for fidmour blank, as I have no idea what it should + be. + (handle_mouse_io): skip bytes until we get to the start of a + packet. My Logitech mouse seems to be passing an extra NULL pad + byte, and GPM does a similar thing here. + (gdk_fb_mouse_ms_open): changed error message to not say psaux, as + this is the ms mouse driver. + (gdk_fb_mouse_ms_packet): fix up button handling, which was + completely broken except for button1. It was checking the wrong + bit in the packet for the status of the right mouse button, and + wrongly assuming right == button2 rather than 3. I fixed that and + also added support for middle button (button2). + 2000-12-08 Havoc Pennington * gtk/gtktextbtree.c (gtk_text_btree_insert): fix breakage here diff --git a/gdk/linux-fb/gdkmouse-fb.c b/gdk/linux-fb/gdkmouse-fb.c index 28a3bf6a15..af50148e01 100644 --- a/gdk/linux-fb/gdkmouse-fb.c +++ b/gdk/linux-fb/gdkmouse-fb.c @@ -193,12 +193,18 @@ send_button_event (GdkFBMouse *mouse, ************ Device specific mouse code ************** ******************************************************/ +/* proto is used to detect the start of the packet: + * (buf[0]&proto[0]) == proto[1] + * indicates start of packet. + */ + struct _GdkFBMouseDevice { char *name; gint packet_size; gboolean (*open)(GdkFBMouse *mouse); void (*close)(GdkFBMouse *mouse); gboolean (*parse_packet)(GdkFBMouse *mouse, gboolean *got_motion); + guchar proto[2]; }; static gboolean handle_mouse_io (GIOChannel *gioc, @@ -223,19 +229,22 @@ static GdkFBMouseDevice mouse_devs[] = 3, gdk_fb_mouse_ps2_open, gdk_fb_mouse_ps2_close, - gdk_fb_mouse_ps2_packet + gdk_fb_mouse_ps2_packet, + { 0xc0, 0x00 } }, { "ms", 3, gdk_fb_mouse_ms_open, gdk_fb_mouse_ms_close, - gdk_fb_mouse_ms_packet + gdk_fb_mouse_ms_packet, + { 0x40, 0x40 } }, { "fidmour", 5, gdk_fb_mouse_fidmour_open, gdk_fb_mouse_fidmour_close, - gdk_fb_mouse_fidmour_packet + gdk_fb_mouse_fidmour_packet, + { 0x00, 0x00 } /* don't know what packet start looks like */ } }; @@ -303,8 +312,9 @@ handle_mouse_io (GIOChannel *gioc, { GdkFBMouse *mouse = (GdkFBMouse *)data; GdkFBMouseDevice *dev = mouse->dev; + guchar *proto = dev->proto; gboolean got_motion; - gint n; + gint n, i; got_motion = FALSE; @@ -313,6 +323,22 @@ handle_mouse_io (GIOChannel *gioc, n = read (mouse->fd, mouse->mouse_packet + mouse->packet_nbytes, dev->packet_size - mouse->packet_nbytes); if (n<=0) /* error or nothing to read */ break; + + /* we just read in what should be the first byte of a packet */ + if (mouse->packet_nbytes == 0) + { + /* check to see if we have the first byte of a packet. + * if not, throw it away */ + while ((mouse->mouse_packet[0] & proto[0]) != proto[1] && n > 0) + { + for (i = 1; i < n; i++) + mouse->mouse_packet[i-1] = mouse->mouse_packet[i]; + n--; + } + /* if none of the bytes read were packet starts, break */ + if (n <= 0) + break; + } mouse->packet_nbytes += n; @@ -451,7 +477,7 @@ gdk_fb_mouse_ms_open (GdkFBMouse *mouse) return FALSE; while ((i = read (fd, buf, sizeof(buf))) > 0) - g_print ("Got %d bytes of junk from psaux\n", i); + g_print ("Got %d bytes of junk from /dev/mouse\n", i); tcgetattr (fd, &tty); tty.c_iflag = IGNBRK | IGNPAR; @@ -482,12 +508,24 @@ gdk_fb_mouse_ms_packet (GdkFBMouse *mouse, int dx=0, dy=0; gboolean new_button1, new_button2, new_button3; guchar *buf; + static guchar prev = 0; buf = mouse->mouse_packet; - new_button1 = (buf[0] & 0x20) && 1; - new_button2 = (buf[1] & 0x10) && 1; - new_button3 = 0; + /* handling of third button is adapted from gpm ms driver */ + if (buf[0] == 0x40 && !(prev|buf[1]|buf[2])) + { + new_button1 = 0; + new_button2 = 1; + new_button3 = 0; + } + else + { + new_button1 = (buf[0] & 0x20) && 1; + new_button2 = 0; + new_button3 = (buf[0] & 0x10) && 1; + } + prev = (new_button1 << 2) | (new_button2 << 1) | (new_button3 << 0); if (*got_motion && (new_button1 != mouse->button_pressed[0] || -- 2.30.2